#include <string.h>
#include <iostream>
using std::cout;
using std::endl;

class Computer{
public:
    Computer(const char * brand,double price)
    : _brand(new char[strlen(brand) + 1]())
    , _price(price)
    {
        strcpy(_brand,brand);
        cout << "Computer(const char *,double)" << endl;
    }

    Computer(const Computer & rhs)
    : _brand(new char[strlen(rhs._brand) + 1]())
    , _price(rhs._price)
    {
        strcpy(_brand,rhs._brand);
        cout << "Computer(const Computer &)" << endl;
    }

    void print(){
        cout << "brand:" << _brand << endl
            << "price:" << _price << endl;
    }

    ~Computer(){
        if(_brand){
            delete [] _brand;
            _brand = nullptr;
        }
        cout << "~Computer()" << endl;
    }
private:
    char * _brand;
    double _price;
};


void test0(){
    /* Computer pc("Acer",4500); */
    /* Computer pc2 = pc; */
    /* pc2.print(); */
}

#if 0
/* void func1(Computer & pc){ */
void func1(Computer pc){
    pc.print();
}

void test1(){
    Computer pc2("shenzhou",3000);
    func1(pc2);
}
#endif

Computer pc3("apple",12000);
/* Computer & func2(){ */
Computer func2(){
    return pc3;
}

void test2(){
    func2().print();
}

int main(void){
    /* test0(); */
    /* test1(); */
    test2();
    return 0;
}
